<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>完善当当购物车页面</title>
    <link type="text/css" rel="stylesheet" href="css/cartStyle.css"/>
</head>
<body>

<div class="content">
    <div class="logo">
        <img src="images/dd_logo.jpg"><span>关闭</span>
    </div>
    <div class="cartList">
        <ul>
            <li>¥<input type="text" name="price" value="21.90"></li>
            <li><input type="button" name="minus" value="-"><input type="text" name="amount" value="1"><input
                    type="button" name="plus" value="+"></li>
            <li id="price0">¥21.90</li>
            <li><p>移入收藏</p>
                <p>删除</p></li>
        </ul>
        <ul>
            <li>¥<input type="text" name="price" value="24.00"></li>
            <li><input type="button" name="minus" value="-"><input type="text" name="amount" value="1"><input
                    type="button" name="plus" value="+"></li>
            <li id="price1">¥24.00</li>
            <li><p>移入收藏</p>
                <p>删除</p></li>
        </ul>
        <ol>
            <li id="totalPrice">&nbsp;</li>
            <li><span onclick="calc()">结 算</span></li>
        </ol>
    </div>
</div>
<script type="text/javascript">
    function calc() { //计算总价
        //获取价格数组
        let prices = document.getElementsByName("price");
        //数量数组
        let amounts = document.getElementsByName("amount");
        let sum = 0;
        for (let i = 0; i < prices.length; i++) {
            //单价 * 数量
            sum += prices[i].value * amounts[i].value;
        }
        document.getElementById("totalPrice").innerHTML = sum;
    }
</script>
</body>
</html>